#include<iostream>
using namespace std;
#include<assert.h>
namespace shiyue{
	class string {
	public:
		string(const char* str = "")
			:_str(new char[strlen(str) + 1])
		{
			_size = strlen(str);
			_capacity = _size;
			strcpy(_str, str);
		}
		string(const string& a)
		{
			_str = new char[strlen(a._str) + 1];
			_size = a._size;
			_capacity = a._capacity;
			strcpy(_str, a._str);
		}

		~string()
		{
			delete[]_str;
			_str = nullptr;
			_size = _capacity = 0;
	  }

		char& operator[](int i) {

			return _str[i];
		}

		size_t size()
		{

			return _size;

		 }

		size_t capacity()
		{

			return _capacity;
		}

		string& operator=(string f)
		{
			
			swaps(f);
			return *this;
		}

		string& swaps(string& c)
		{
			swap(_str, c._str);
			swap(_size, c._size);
			swap(_capacity, c._capacity);
			return c;
	   }
		void push_back(char c)
		{
			if (_size == _capacity)
			{
				_capacity = _capacity == 0 ? 2 : 2*_capacity;
				char*tempt= new char[_capacity + 1];
				strcpy(tempt, _str);
				delete[] _str;
				_str = tempt;				
			}
			_str[_size++] = c;
			_str[_size]='\0';
		 }
		void resize(int i, char ch='\0')
		{
			if (i < size())
			{
				_str[i-1] = '\0';
			}
			else
			{
				reserve(i);
				for (int j = 0; j < i - size(); )
				{
					push_back(ch);
				}
			}
		}
		string& insert(size_t pos, char ch)
		{
			assert(pos<=_size);
			
			if (_size == _capacity)
			{
				reserve(_size + 1);
			}
			for (int i=0; i < _size - pos; i++)
			{
				_str[_size-i] = _str[_size - 1-i];
			}
			_str[pos] = ch;
			_size++;
			return*this;
		}
		string& erase(size_t pos)
		{
			assert(pos <=_size);
			for (int i=0; i <=_size - pos+1; i++)
			{
				_str[pos + i-1] = _str[pos + i ];
			}
			_size--;
			return *this;
		}
		string& reserve(int i)
		{
			_capacity = i;
			char* tempt = new char[_capacity + 1];
			strcpy(tempt, _str);
			delete[]_str;
			_str = tempt;
			return *this;
		}

	private:
		char*_str;
		size_t _size;
		size_t _capacity;
	};
	


}